package filter;

import javax.servlet.*;
import java.io.IOException;

public class FilterEncoding implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
//        设置请求中的字符编码
        request.setCharacterEncoding("utf-8");
//        调用下一个过滤器或者web资源
        filterChain.doFilter(request,response);
//        设置响应中的字符编码格式
        response.setContentType("text/html;charset=utf-8");
    }

    @Override
    public void destroy() {

    }
}
